<template>
    <div><br>
   <!-- 添加病历 -->
      <el-form ref="formData" :model="form" label-width="100px">
        <el-form-item label="病人姓名">
          <el-input :value="patient.name"></el-input>
        </el-form-item>

        <el-form-item label="病情描述" prop="ciDescription">
          <el-input type="textarea" v-model="form.ciDescription" placeholder="请输入病情描述"></el-input>
        </el-form-item>
        
        <el-form-item label="填写医生">
          <el-input :value="doctor.docName"></el-input>
        </el-form-item>
      <el-form-item>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确认</el-button>
    </el-form-item>
</el-form>
<span style="color: red;">{{ msg }}</span>
</div>
</template>

<script>
export default {
    props: {
        caseId:{
            type: Number,
            required: true
        }
    },
    data(){
        return{
            doctor:{},
            patient:{},
            form: {
                ciDescription: '',
                ciCaseId: ''
            },
            msg:''
        }
    },
    methods:{
        //添加病历的方法
        handleSubmit() {
            if(this.form.ciDescription==null || this.form.ciDescription==''){
                this.msg='请输入病情描述'
                return
            }
        // 在这里执行添加病历的操作，可以发送请求到后端等
        this.form.ciWorkerId=this.doctor.id//医生id
        this.form.ciCaseId=this.patient.id//病人id
        this.$axios.post("api/doctor/addPR",this.form)
            .then(res=>{
                if(res.data.code==200){
                this.$message.success("添加病历成功")
                this.closeDialogWithData()
            }
        })
        },
        //查找医生信息
        queryDoctor(){
        this.$axios.get("api/doctor/queryDoctor")
        .then(res=>{
            if(res.data.code==200){
                this.doctor=res.data.data;
            }
        })
        },
        //查找病人信息
        queryPatient(){
            this.$axios.get("api/doctor/queryPatient/"+this.caseId)
            .then(res=>{
            if(res.data.code==200){
                this.patient=res.data.data;
                console.log(this.patient)
            }
        }) 
        },
        closeDialogWithData() {
            // 触发事件并传递数据给父组件
            this.$emit('closeDialog', this.caseId); // 替换 dataToPass 为你想要传递的数据
        }
    },
    created(){},
    mounted(){
        this.queryDoctor()
        this.queryPatient()
    }
}
</script>

<style>

</style>